Ext.define('Seq.form.field.TextArea', {
    extend: 'Ext.form.field.TextArea',
    xtype: 'xtextareafield',

    grow: false,
    enableKeyEvents: true,

    allowTab: true,
    tabText: '\t',

    listeners: {
        keydown: function (cmp, e) {
            if (cmp.allowTab && (e.getKey() == e.TAB)) {
                e.stopEvent();
                cmp.insertAtCursor(cmp.inputEl.dom, cmp.tabText);
            }
        }
    },

    //插入TabText字符，并重新计算输入光标的位置
    insertAtCursor: function (el, ins) {
        if (el.setSelectionRange) {
            let withIns = el.value.substring(0, el.selectionStart) + ins;
            let pos = withIns.length;
            el.value = withIns + el.value.substring(el.selectionEnd, el.value.length);
            el.setSelectionRange(pos, pos);
        } else if (document.selection) {
            document.selection.createRange().text = ins;
        }
    },
});